#pragma once 
#include <iostream>
#include <fstream> // 包含文件流头文件，用于文件操作
using namespace std;

// 定义电池模块类
class Battery {
public:
    string voltage;      // 电压
    string capacity;     // 容量
    string supplyVoltage;// 对外供电电压
    float chargingTime;  // 充电时长

    // 默认构造函数
    Battery()
        : voltage("0V"), capacity("0Ah"), supplyVoltage("0V"), chargingTime(0.0f) {}

    // 构造函数
    Battery(string v, string c, string sv, float ct)
        : voltage(v), capacity(c), supplyVoltage(sv), chargingTime(ct) {}

    // 各属性的set方法
    void setVoltage(string newVoltage) {
        voltage = newVoltage;
    }

    void setCapacity(string newCapacity) {
        capacity = newCapacity;
    }

    void setSupplyVoltage(string newSupplyVoltage) {
        supplyVoltage = newSupplyVoltage;
    }

    void setChargingTime(float newChargingTime) {
        chargingTime = newChargingTime;
    }

    // 打印电池模块信息
    void print() {
        cout << "电池电压: " << voltage << "V" << endl;
        cout << "电池容量: " << capacity << "Ah" << endl;
        cout << "对外供电电压: " << supplyVoltage << "V" << endl;
        cout << "充电时长: " << chargingTime << "小时" << endl;
    }

    // 保存电池模块信息到本地文件
    void save(const string &filename) {
        ofstream outFile(filename, ios::app);  // 以追加模式打开文件
        if (!outFile.is_open()) {
            cerr << "无法打开文件 " << filename << endl;
            return;
        }
        outFile << "电池电压: " << voltage << "V" << endl;
        outFile << "电池容量: " << capacity << "Ah" << endl;
        outFile << "对外供电电压: " << supplyVoltage << "V" << endl;
        outFile << "充电时长: " << chargingTime << "小时" << endl;
        outFile.close();  // 关闭文件流
    }
};